简体   繁体   English

需要帮助附加Javascript onclick

[英]need help appending Javascript onclick

Hi I'm trying to append javascript code when I click a button, but I think I messed up. 嗨,当我点击按钮时,我正在尝试附加javascript代码,但我想我搞砸了。 If someone could help me with syntax. 如果有人可以帮我解决语法问题。 Maybe I'm doing it the wrong way; 也许我做错了; if someone has a better way to do it, it would be appreciated. 如果有人有更好的方法,我们将不胜感激。

$("#btn_add").click(function(){   
 '<script>$(".selectcategory'+count+'").change(function() {var vv = ($(this).val());$( ".cat'+count+'" ).empty();$(".cat'+count+'").append("<input id="i_index" type="text" name="categorie[]" maxlength="255" style="width:80%" value="vv">");});</script>'
});

Honostly there is a lot wrong in your code. 你的代码中存在很多错误。 I am learning Javascript myself at the moment, so maybe i won't provide the solution, but I am trying to help. 我现在正在学习Javascript,所以也许我不会提供解决方案,但我正在努力提供帮助。

First of all, the script tag should be arround your code, not in it. 首先,脚本标记应该是代码,而不是代码。 Second use the single and double quotes correct. 第二次使用单引号和双引号正确。 Last but not least, use some markup in your code. 最后但并非最不重要的是,在代码中使用一些标记。 It's hard to see where the issue is. 很难看出问题出在哪里。

<script>
$("#btn_add").click(function()
{   
    $(".selectcategory"+count).change(function()
    {
       var vv = ($(this).val());
       $(".cat"+count).empty();
       $(".cat"+count).append('<input id="i_index" type="text" name="categorie[]" maxlength="255" style="width:80%" value="vv">');
    });
});
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM