我有这个代码
<script>
function cA( url )
{
document.myform.action = url;
}
</script>
<input type="whatever" name="whatever" id="whatever" />
<button class="whatever-button" id="defaultAction" value="Go for it" name="whatever" type="submit" onClick="cA('whatever.php#anchor')" >Go for it
</button>
当您单击 Go for it 按钮时,whatever.php#anchor
正在加载。我如何需要更改输入标记的元素才能执行与cA('whatever.php#anchor')
单击按钮相同的操作?
因此,当用户在该字段中按下回车键时,whatever.php#anchor
应该加载该站点,或者更具体地说,cA('whatever.php#anchor')
应该执行该站点。
该页面有更多按钮,因此将一个按钮设为默认按钮不起作用。
PS:
将所有内容包装在一种形式中不起作用,因为页面的结构是
<form>
<script>
function cA( url )
{
document.myform.action = url;
}
</script>
<input type="whatever1" name="whatever1" id="whatever1" />
<button class="whatever1-button" id="defaultAction1" value="Go for it" name="whatever1" type="submit" onClick="cA('whatever.php#anchor1')" >Go for it
</button>
<input type="whatever2" name="whatever2" id="whatever2" />
<button class="whatever2-button2" id="defaultAction2" value="Go for it" name="whatever2" type="submit" onClick="cA('whatever.php#anchor2')" >Go for it
</button>
<input type="whatever3" name="whatever3" id="whatever3" />
<button class="whatever3-button" id="defaultAction3" value="Go for it" name="whatever3" type="submit" onClick="cA('whatever.php#anchor3')" >Go for it
</button>
...
</form>