Javascript Jquery使用另一个js脚本访问附加元素id
我试图调用一个HTML元素上的js函数,我已经使用JQUERY将它附加到页面上Javascript Jquery使用另一个js脚本访问附加元素id,javascript,jquery,function,append,getelementbyid,Javascript,Jquery,Function,Append,Getelementbyid,我试图调用一个HTML元素上的js函数,我已经使用JQUERY将它附加到页面上 <body> <div id='father'> </div> <input type="submit" value="choice one" onclick='choice_one()'/> <input type="submit" value="choice two" onclick='choice_two()'
<body>
<div id='father'>
</div>
<input type="submit" value="choice one" onclick='choice_one()'/>
<input type="submit" value="choice two" onclick='choice_two()'/>
<input type="submit" value="choice three" onclick='choice_three()'/>
</body>
我的jQuery在js函数中
<script>
function choice_one(){
var container = "<div id='field'>
<form>
<input type="text" id='choice_one_answer' value="" />
<input type="submit" value="submit" onclick='answer_one()'/>
</form>
</div>";
$('ul#field').remove();
$("div#father").append(container);
}
function choice_two(){
var container = "<div id='field'>
<form>
<input type="text" id='choice_two_answer1' value="" />
<input type="text" id='choice_two_answer3' value="" />
<input type="submit" value="submit" onclick='answer_two()'/>
</form>
</div>";
$('ul#field').remove();
$("div#father").append(container);
}
</script>
函数选择_one(){
变量容器=”
";
$('ul#field')。删除();
$(“div#father”).append(容器);
}
函数选择_two(){
变量容器=”
";
$('ul#field')。删除();
$(“div#father”).append(容器);
}
所以第三部分是使用答案和js,然后重新加载另一个字段。然后加载另一个函数-->新建应答字段
<script>
function answer_one(){
var answer = document.getElementById('choice_one_answer');
do something with answer...
choice_two();
}
function answer_two(){
var answer_one = document.getElementById('choice_two_answer1');
var answer_two = document.getElementById('choice_two_answer2');
do something with answer...
choice_one();
}
other functions....
</script>
函数answer_one(){
var answer=document.getElementById('choice\u one\u answer');
用答案做点什么。。。
选择二();
}
函数answer_two(){
var answer\u one=document.getElementById('choice\u two\u answer1');
var answer\u two=document.getElementById('choice\u two\u answer2');
用答案做点什么。。。
选择一;
}
其他职能。。。。
因此,当我尝试调用js函数如answer_one()/answer_two()时,函数无法从输入Id的--->中获取变量,我认为这是因为加载页面时没有加载元素
是否有jQuery/js解决方案用于此。。。有什么想法吗
有这样的解决方法吗???为什么使用jQuery而不使用
$()
/jQuery()
选择器来选择元素
尝试将
/$('ul#id').remove()
行和dupm$('ul#id').size()注释到控制台,以便知道您的元素存在。我认为在一行中附加html是一种很好的做法,如下所示:
var container = "<div id='field'><form><input type="text" id='choice_one_answer' value="" /><input type="submit" value="submit" onclick='answer_one()'/></form></div>";
var container=”“;
没有时间测试任何东西,但是用于访问插入代码的jQuery变通方法是.live()