使用方法 onclick () 触发一个函数,该函数打开它从单击按钮抓取的窗口
using the method onclick () to trigger a function that opens a window it grabs from the clicked button
<script language="JavaScript">
function goThere()
{
var the_url = window.document.form.button.value;
var good_url = fixURL(the_url);
var new_window = window.open(good_url,"new_window","menubar,resizeable");
}
function fixURL(the_url)
{
var the_first_seven = the_url.substring(0,7);
the_first_seven = the_first_seven.toLowerCase();
if (the_first_seven != 'http://')
{
the_url = "http://" + the_url;
}
return the_url;
}
</script>
</head>
<body>
<form name="the_form" onclick="goThere()"; return false;">
<input type="button" name="the_url" class="broadGroups" onClick="goThere()" value="http://en.wikipedia.org/wiki/Category:Sports"></input>
<input type="button" name="the_url" class="broadGroups" onclick="goThere()" value="http://en.wikipedia.org/wiki/Category:Film"></input>
</form>
</body>
</html>
所以这段代码可能完全搞砸了,但这就是我正在尝试做的。
标签内有两个按钮。我希望每个人都使用 onsubmit 方法来触发函数 goThere((。如何设置它,以便将the_url设置为我从按钮标签中提取的值。我还希望能够在按钮本身上放置非 url 文本,同时允许它通过方法 call onsubmit 调用 goThere((。
最后,它应该只获取 url,确保它以 http://开头(在这种情况下没关系,因为用户没有输入 url,但我想稍后将其保留用于其他目的(并在带有菜单栏和可调整大小属性的新窗口中打开它。
对不起,长帖子。任何帮助将不胜感激。
在
goThere
呼叫中传入this
。这会将点击的元素引入您的 goThere 函数。然后,访问单击按钮的属性。
http://jsfiddle.net/wJMgb/
onClick="goThere(this)"
function goThere(elem) {
var the_url = elem.value;
var good_url = fixURL(the_url);
var new_window = window.open(good_url, "new_window", "menubar,resizeable");
}
function fixURL(the_url) {
var the_first_seven = the_url.substring(0, 7);
the_first_seven = the_first_seven.toLowerCase();
if (the_first_seven != 'http://') {
the_url = "http://" + the_url;
}
return the_url;
}
相关文章:
- Javascript onclick函数会立即调用(而不是在单击时调用)
- Javascript在处理函数时防止单击
- JavaScript-onClick将按钮ID或单击按钮的文本传递给函数
- 使用单击函数中的jQuery切换元素
- 单击函数仅对某些数据名称执行
- 如何在单击、Knockout时传递函数中的值
- 如何创建背景图像列表'URL,并使用jQuery在单击函数时应用它们
- 运行“;非“;单击另一个函数中的函数仅一次
- 调用函数和单击动画
- 如何在单击组件时调用函数
- 单击从子函数返回父函数
- 调用函数单击选择标签中的选项
- jQuery 函数 - 单击两次返回一个值
- 模式弹出窗口无法正常工作,它多次调用函数 - 单击事件处理程序运行多次
- 在 JSON 解析中添加函数单击
- 调用多个函数单击“反应JS”
- 如何在使用javascript函数单击网格时设置文本框值
- 如何通过使用onClick()函数单击按钮来填充Javascript中的表
- 我如何添加多个值从一个选择列表框到另一个列表框上使用javascript函数单击按钮
- 手动触发函数单击事件对象