解决方案 »
- 请大家帮我看下这段代码,jquery的
- 一个项目中(是一个大公司的项目)碰到的一个js问题求助高手
- 这两个this指针怎么不相同呢?
- 学习JQuery遇见的问题~~~~~~~~~~帮忙解决一下
- 请教:关于动态生成元素的事件问题
- 延迟效果
- js中这个程序为什么会出错??究竟是什么含义?
- 各位大哥帮帮忙!怎样做一个站内搜索!
- ?如何在自己的窗口中(IE浏览器),用Javascript使菜单地址栏等隐藏??快快。(souhay)
- 又要麻烦各位了,如何使onunload只在关闭窗口时触发,而页面刷新的时不触发
- 点击后展开输入框,并隐藏自身
- Jquery 怎么实现加载完页面后自动将img和a中的地址替换
<html>
<head>
<title></title>
</head>
<body>
<input type="button" value="b1" /><input type="text" />
<input type="button" value="b2" /><input type="text" />
<input type="button" value="b3" /><input type="text" />
<input type="button" value="b4" /><input type="text" />
<script>
var inputs=document.getElementsByTagName('input'),
bs=[],ts=[];
for(var i= 0,len=inputs.length;i<len;i++){
var type=inputs[i].type;
if(type=='button'){
bs.push(inputs[i]);
}
if(type=='text'){
ts.push(inputs[i]);
}
}
function findIndex(dom){
for(var i= 0,len=bs.length;i<len;i++){
if(bs[i]==dom){
return i;
}
}
return -1;
}
document.body.onclick=function(e){
var a=e||window.event,
target= a.srcElement|| a.target;
if(target.type=='button'){
ts[findIndex(target)].value=target.value;
}
}
</script>
</body>
</html>
function down(id)
{
document.getElementById(id).value++;
}
function up(id)
{
document.getElementById(id).value--;
}
</script>
<input type="text" id="id0" value="1"/><input type="button" value="+" onclick="down('id0')"/><input type="button" value="-" onclick="up('id0')"/><br />
<input type="text" id="id1" value="1"/><input type="button" value="+" onclick="down('id1')"/><input type="button" value="-" onclick="up('id1')"/><br />
<input type="text" id="id2" value="1"/><input type="button" value="+" onclick="down('id2')"/><input type="button" value="-" onclick="up('id2')"/><br />
<input type="text" id="id3" value="1"/><input type="button" value="+" onclick="down('id3')"/><input type="button" value="-" onclick="up('id3')"/><br />
<input type="button" class='btn' value="btn1" /><input type="text" />
<input type="button" class='btn' value="btn2" /><input type="text" />
<input type="button" class='btn' value="btn3" /><input type="text" />
<input type="button" class='btn' value="btn4" /><input type="text" /><script>
$(".btn").click(function(){
var a='www.ljiong.com';
$(this).next('input').val(a);
})
</script>
按钮和文本框也是用 JS 添加的, 但是两个的位置没在一起, 也没ID
window.onload = function() {
document.body.onclick = function(e) {
e = e || event;
var el = e.target || e.srcElement;
if(el.type != 'button') return;
var x = document.getElementsByTagName('input');
var b = 0, t = 0;
for(var i=0; i<x.length; i++) {
if(x[i].type == 'button') {
if(x[i] == el) break;
b++;
}
}
for(var i=0; i<x.length; i++) {
if(x[i].type == 'text') {
if(t == b) {
x[i].focus();
break;
}
t++;
}
}
}
}
</script>
<body>
<div>
<input type="button" value="btn1" />
<input type="button" value="btn2" />
<input type="button" value="btn3" />
<input type="button" value="btn4" />
</div>
<div>
<input type="text" />
<input type="text" />
<input type="text" />
<input type="text" />
</div>
</body>
无论按钮和文本框是如何产生的,都将按生成次序一一对应
$(document).on('click', '[type=button]', function() {
var that = this;
$('[type=button]').each(function(i) {
if(that == this) $('[type=text]').eq(i).focus();
})
})
})