- 现在正在工作,谢谢!
我已经阅读过关于它在JSFiddle上运行的其他问题,但没有在网站上阅读,而且大多数问题与未将其设置为dom准备好有关,但是,这是我第一次使用JSQuery(实际上,我用JS做过的最多就是警报),所以我不知道我做错了什么。
我现在正在使用PHP项目,我喜欢使用header.php,index.php和footer.php。我在header.php文件中添加了jquery.js的链接(是的,我确定这是文件名,它是1.6.4的未压缩版本,这就是我的标题:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WebTools</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="ddaccordion.js"></script>
<script type="text/javascript">
ddaccordion.init({
headerclass: "submenuheader", //Shared CSS class name of headers group
contentclass: "submenu", //Shared CSS class name of contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
animatedefault: false, //Should contents open by default be animated into view?
persiststate: true, //persist state of opened contents within browser session?
toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["suffix", "<img src='images/plus.gif' class='statusicon' />", "<img src='images/minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
//do nothing
},
onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
//do nothing
}
})
</script>
<script type="text/javascript">
$(document).ready(function() {
$('.ask').jConfirmAction();
});
</script>
<script language="javascript" type="text/javascript" src="niceforms.js"></script>
<link rel="stylesheet" type="text/css" media="all" href="niceforms-default.css" />
</head>
<body>
我有另一个文件,我稍后将其插入到位。 我是否在form.php文件之前或之内放置了我的header.php,它似乎不起作用。我真的很想有人调查一下,告诉我这是怎么回事!它可能是微不足道的,应该不是什么大不了的事,但对我来说还是新手,请跟我说。
这是我的脚本和我的HTML: *我没有添加任何PHP,因为我无法使表单正常工作
<script language="javascript">
$(document).ready(function () {
var scntDiv = $('#p_scents');
var i = $('#p_scents p').size() + 1;
$('#addScnt').live('click', function () {
$('<p><label for="p_scnts"><input type="text" id="p_scnt" size="20" name="p_scnt_' + i + '" value="" placeholder="Item" /></label><label for="count"><input type="text" id="count" size="20" name="count' + i + '" value="" placeholder="Amount" /></label> <a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
i++;
return false;
});
$('#remScnt').live('click', function () {
if (i > 2) {
$(this).parents('p').remove();
i--;
}
return false;
});
var sctaDiv = $('#p_scentz');
var i = $('#p_scentz p').size() + 1;
$('#addScntz').live('click', function () {
$('<p><label for="p_scntz"><input type="text" id="p_scntz" size="20" name="p_scntz_' + i + '" value="" placeholder="Item" /></label><label for="ocount"><input type="text" id="ocount" size="20" name="ocount' + i + '" value="" placeholder="Amount" /></label> <a href="#" id="remScntz">Remove</a></p>').appendTo(sctaDiv);
i++;
return false;
});
$('#remScntz').live('click', function () {
if (i > 2) {
$(this).parents('p').remove();
i--;
}
return false;
});
var sctbDiv = $('#a_scentz');
var i = $('#a_scentz p').size() + 1;
$('#addScnta').live('click', function () {
$('<p><label for="a_scntz"><input type="text" id="a_scntz" size="20" name="a_scntz_' + i + '" value="" placeholder="Item" /></label> <a href="#" id="remScnta">Remove</a></p>').appendTo(sctbDiv);
i++;
return false;
});
$('#remScnta').live('click', function () {
if (i > 2) {
$(this).parents('p').remove();
i--;
}
return false;
});
});
</script>
<form action="" method="post">
<div id="p_scents">
<p>Input</p>
<p>
<label for="p_scnts">
<input type="text" id="p_scnt" size="20" name="p_scnt" value="" placeholder="Item" />
</label>
<label for="count">
<input type="text" id="count" size="20" name="count" value="" placeholder="Amount" />
</label> <a href="#" id="addScnt">Add Another</a>
</p>
</div>
<div id="p_scentz">
<p>Output</p>
<p>
<label for="p_scntz">
<input type="text" id="p_scntz" size="20" name="p_scntz" value="" placeholder="Item" />
</label>
<label for="ocount">
<input type="text" id="ocount" size="20" name="ocount" value="" placeholder="Amount" />
</label> <a href="#" id="addScntz">Add Another</a>
</p>
</div>
<div id="a_scentz">
<p>Groups</p>
<p>
<label for="a_scntz">
<input type="text" id="a_scntz" size="20" name="a_scntz" value="" placeholder="Item" />
</label> <a href="#" id="addScnta">Add Another</a>
</p>
</div>
<p>
<input type="submit" name="submit" id="submit" value="Submit" />
<input type="reset" name="Reset" id="submit" value="Reset" />
</p>
</form>
这是我的JSFiddle链接
谢谢你的时间!