我正在尝试根据用户提供的数字添加输入框。在我的 addexercises() 被调用之前,jquery 函数工作正常,但是在它被调用之后它不再工作。
编辑:基本上,在 addexercise() 执行后,当我单击“文本框”类的某些内容时,我的 jquery 函数不再起作用。在 addexercise() 执行之前,它工作正常。我不明白为什么它会破裂。
这是我的 addworkout.js 文件
$(document).ready(function () {
$(".textbox").click (function () {
alert('working');
});
});
function addexercises() {
var numexercise = document.getElementById("numexercises");
var totalexercise = 0 ;
document.getElementById("exercisesthisworkout").style.display = "none";
if (parseInt(numexercise.value) && parseInt(numexercise.value) < 25 && totalexercise < 25) {
totalexercise += parseInt(numexercise.value);
for ( var i = 0; i < parseInt(numexercise.value); i++) {
// alert("hello world");
var subcontainer = '<div class="exercisecontainer">';
var exercisename = '</br><input type="text" value="Enter Exercise Name" class="textbox" name="exercisename">';
var numsets = '<br><input type="text" value="Number of Sets" class="numsets" name="numsets">';
var endingdiv = "</div>";
subcontainer += exercisename;
subcontainer += numsets;
subcontainer += endingdiv;
document.getElementById("workoutentrycontainer").innerHTML += subcontainer;
//document.getElementById("workoutentrycontainer").innerHTML += exercisename;
//document.getElementById("workoutentrycontainer").innerHTML += numsets
//document.getElementById("workoutentrycontainer").innerHTML += endingdiv;
}
}
}
和我的html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="/static/addworkout.css" type="text/css">
<script type="text/javascript" src="/static/jquery.js"> </script>
<script type="text/javascript" src="/static/addworkout.js"></script>
</head>
{% extends "masterpage.html" %}
{% block content %}
<body>
<div id="workoutentrycontainer">
<div id="exercisesthisworkout">
<p>How many unique exercises</p>
<input type="text" class="textbox" id="numexercises">
<input type="button" class="button" onclick="addexercises()" value="Add" id="numexercisesbutton">
</div>
</div>
</body>
{% endblock %}
</html>
在此先感谢您的帮助!