当我点击A标签时 如何用jq获取 text文本框里的文本如何通过dom关系获取 text文本中的值
问题描述:
<div class="wen4"><img src="~/BooxCssJsImg/img/che1.png" border="0"/> <a href="#" onclick="purchase('@item.BookName')">购买</a> | <img src="~/BooxCssJsImg/img/da.png"/><a href="#">数量:</a> <input type="button" value="+" class="input2" style="width:20px"/ > <input type="text" style="width:20px;margin-left:140px"; id="input1" value="0"/> <input class="input3" type="button" value="-" style="width:20px"/> </div>
当我点击A标签时 如何用jq获取 text文本框里的文本 不考虑用id或者class获取 如何通过dom关系获取 text文本中的值 求教 多谢!
答
给a标签添加一个点击事件 onclick="一个函数名(this)"
后面写一个函数
function 这个函数名(dom){
var text=$(dom).siblings("input[type='text']").val();//获取它的值
}
这样就可以实现了吧。
答
<a href="#" onclick="purchase('@item.BookName',this)">购买</a>
function purchase(name,el){
var input=$(el).parent().find(':text');
alert(input.value)
}
答
a标签里面添加事件onclick="purchase(this)"
purchase(text){
var msg = $(text).text();
}
答
$(this).siblings("input[type='text']").val();
答
a标签里添加时间 onclick = "getdata(this)"
js方法里
function getdata(dom)
{
var text = $(dom).siblings("input[type='text']").val();
}
//text即为所需内容