gpt4 book ai didi

html - 表单提交按钮 onClick JavaScript 函数

转载 作者:行者123 更新时间:2023-11-30 10:47:37 25 4
gpt4 key购买 nike

我制作了一个带有单选按钮和提交按钮的简单表单。提交时,会调用 check() 函数,并根据选择的单选按钮打印出文本。

但是,它只有在我第二次提交时才有效。我第一次提交,页面刷新,?req=on 添加到 url 中,仅此而已。

为什么会这样,我怎样才能让它在每次按下提交按钮时都起作用?

HTML:

<form name="request" onsubmit="return check();">
<p>
<label>Pick fragments: </label>
</p>
<fieldset>
<input id="rally" type="radio" name="req" />
Longest rally
<br />
<input id="gamept" type="radio" name="req" />
Game points
<br />
<input id="setpt" type="radio" name="req" />
Set points
<br />
<br />
<input type="submit" />
</fieldset>
</form>

<ul id="uri"></ul>

和部分脚本:

function check() {

window.location.hash = "article6";
var uri = new Array();
var vid = new Array();
$('#uri').empty();

if($('#rally')[0].checked) {

//get json with the longest rally and print it out
$.getJSON('json/longRally.json', function(json) {
for(var i = 0; i < json["results"]["bindings"].length; i++) {
uri[i] = json["results"]["bindings"][i]["longRally"].value
vid[i] = json["results"]["bindings"][i]["uriRally"].value

};

uri.sort(alphanum);
vid.sort(alphanum);

for(var i = 0; i < json["results"]["bindings"].length; i++) {
$('#uri').append('<li><a href="' + vid[i] + '">' + uri[i] + '</a></li>');
};
});
}
}

网站位于此处:

http://b-webdesign.com/multilab/Ver3.0/#article6

最佳答案

添加:

return false;

到你的函数结束。

关于html - 表单提交按钮 onClick JavaScript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7337981/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com