javascript - 如何正确添加div block ?

标签 javascript jquery html css

我有以下代码将简单文本更改为 textarea 字段:

        $('.field').live({      
            mouseenter:
                function()
                {
                    title='<?php echo $user_title; ?>';
                    old_value=$(this).text();
                    item_id=$(this).attr('id');
                    item=$(this).parent('td');
                    height=event.target.offsetHeight;
                    width=event.target.parentNode.offsetWidth;
                    new_value=(old_value=='Not translated') ? '' : old_value;
                    $(this).empty();
                    var field=(title=='Login') ? "<textarea style='vertical-align: middle; font-family: Helvetica; font-size: 12pt; width: 212px;' id='new_value' name='term'>" + new_value + "</textarea>" 
                                : "<textarea style='vertical-align: middle; font-family: Helvetica; font-size: 12pt; width: 212px;' id='new_value' name='term'>" + new_value + "</textarea><div id='save_button' class='btn btn-primary' href='#'>>></div>";
                    $(this).html(field);
                    $("#new_value").height(height);
                    button_id=item_id.split('/')[0];
                    button_id=button_id.replace(/([!"#$%&'()*+,./:;<=>?@\[\\\]^`{|}~])/g, "\\$1");
                    $("#"+button_id).show();

                    $("#new_value").click(function()
                    {
                        if (title=='Login') 
                            window.location.replace('<?php echo $fb_url?>');
                    });
                },
            mouseleave:
                function()
                {
                    $(this).empty();
                    $(this).html(old_value);
                    $("#"+button_id).hide();
                    alert($(this).html());
                }
            }
        );

文本的 div block :

echo "<td width='250'><div class='field' id='".$record['translate']['label_value']."/".$record['language_id']."'>".
strip_tags($record['translate']['coalesce(loc.language_value)'])."</div>";

它工作正常,但我需要添加额外的 div block :

echo "<td width='250'><div class='field' id='".$record['translate']['label_value']."/".$record['language_id']."'><div style='width: 200px;'>".
strip_tags($record['translate']['coalesce(loc.language_value)'])."</div></div>";

此操作后我的代码不起作用!它将文本更改为 textarea 字段,但在“mouseleave”事件中它不起作用 $(this).empty() 构造!请告诉我,我该如何解决?

最佳答案

尝试关闭标签

echo "<td width='250'><div class='field' id='".$record['translate']['label_value']."/".$record['language_id']."'><div style='width: 200px;'>".strip_tags($record['translate']['coalesce(loc.language_value)'])."</div></div></td>";

我在最后添加了

关于javascript - 如何正确添加div block ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11536338/

相关文章:

javascript - Prestashop : Uncaught SyntaxError: Unexpected token chrome only

javascript - 输入内容未正确填写

javascript - Adobe DTM 无法将 Angular 变量识别为数据元素

javascript - 如果 Select2 字段为空,LiveValidation 将提交表单而不验证其他字段

html - CSS 边框显示问题,不适用于 Chrome 和 Safari

javascript - 60fps : How to use requestAnimationFrame the right way?

javascript - 向上和向下调整滚动位置到最近的包装器 div

javascript - 使用 jquery.html() 将 html 元素保存到数据库

Javascript 变音符号不敏感搜索

javascript - Electron 上的多个http页面