html()真的取代了html代码吗?

时间:2015-03-16 22:52:35

标签: javascript jquery html

我有一些像这样的HTML代码,

<form action="abc.html" method="post">
   <div id = "result">
      <input type="hidden" value="1" name="banner">
   </div>
</form>

然后我得到一些Jquery代码来替换这个div中的内容,

var temp = "<input type='hidden' value='1' name='banner'>"
$(".result").html(temp);

然后我提交表单,我发现form.banner中有两个值, 的 form.banner = 1,1

我错了吗?或者我必须首先使用某些东西来清除数据然后使用html()? 非常感谢!

2 个答案:

答案 0 :(得分:-1)

用#result替换.result。你试图定位一个类,但你的div包含一个id。

答案 1 :(得分:-2)

当你使用$(“。result”)。html(temp)时,它将匹配class =“result”。 你想使用$(“#result”)。html(temp)匹配id =“result”。

相关问题