Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery在包装时更改元素_Javascript_Jquery_Html - Fatal编程技术网

Javascript Jquery在包装时更改元素

Javascript Jquery在包装时更改元素,javascript,jquery,html,Javascript,Jquery,Html,我使用Jquery从服务器获取响应,并使用以下代码将响应中的特定元素替换为该元素: //msg is the returned message from the response //$row is the element being replaced var $newRow = $(msg).find('#'+$row.attr('id')); $row.replaceWith($newRow); 现在,msg中有一个选择框,包含以下html代码(包括外部元素): 这里有什么问题?选择标记

我使用Jquery从服务器获取响应,并使用以下代码将响应中的特定元素替换为该元素:

//msg is the returned message from the response
//$row is the element being replaced
var $newRow = $(msg).find('#'+$row.attr('id'));
$row.replaceWith($newRow);
现在,msg中有一个选择框,包含以下html代码(包括外部元素):



这里有什么问题?

选择标记是自动关闭的,请注意结尾处的/>:

<select data-field="monetary_unit" value="12" disabled/> <== here

如果在第一个代码段中查看,您会看到“select”元素如下所示:

<select data-field="monetary_unit" value="12" disabled/>

注意末尾的“/”吗? 从服务器获取的HTML格式不正确,并且SELECT元素被视为void元素。void元素是没有close标记的元素,例如

<select data-field="monetary_unit" value="12" disabled/> <== here
<select data-field="monetary_unit" value="12" disabled/>