请教一个input type="text"和Label问题

baibai620 2012-08-16 04:27:46

<td><input type="text" id="t1p1z11" runat="server" class="imgbutton" value="0" title="1厅1排11座" readonly="readonly"></td>
<td><input type="text" id="t1p1z9" runat="server" class="imgbutton" value="0" title="1厅1排9座" readonly="readonly"></td>
<td><input type="text" id="t1p1z7" runat="server" class="imgbutton" value="0" title="1厅1排7座" readonly="readonly"></td>
<label id="Label1"></label>

请教如何点击一次input type="text"就在label里显示对应的title,再点击一次label就去掉对应的title,我知道要用JS,但我对JS不是很熟悉,哪位大哥指点下?
...全文
331 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
观光客 2012-08-17
  • 打赏
  • 举报
回复
$(document).ready(function() {
var reslut = "";

$(".imgbutton").click(function() {
if ($.inArray($(this).attr("title"), reslut.split(",")) < 0) {
reslut += $(this).attr("title") + ",";
$("#Label1").html(reslut.substring(0, reslut.length - 1));
}
else {
reslut = reslut.replace($(this).attr("title")+",", "");
$("#Label1").html(reslut.substring(0, reslut.length - 1));
}
})
});
baibai620 2012-08-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
<script type="text/javascript">
$(document).ready(function() {
$("input:text").click(function(){
$("#Label1").html($(this).attr("title"));
})
})
添加一下jquery引用
[/Quote]
虽然,没全部解决我的问题,但还是谢谢你给的思路,已经解决了
happytonice 2012-08-16
  • 打赏
  • 举报
回复
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script src="jquery.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function() {
$(".imgbutton").click(function(){
$("#Label1").html($(this).attr("title"));
})
})

</script>
</head>
<body>
<form id="form1" runat="server">
<table>
<tr>
<td><input type="text" id="t1p1z11" runat="server" class="imgbutton" value="0" title="1厅1排11座" readonly="readonly"></td>
<td><input type="text" id="t1p1z9" runat="server" class="imgbutton" value="0" title="1厅1排9座" readonly="readonly"></td>
<td><input type="text" id="t1p1z7" runat="server" class="imgbutton" value="0" title="1厅1排7座" readonly="readonly"></td>
</tr>
</table>
<label id="Label1"></label>
</form>
</body>
</html>

已测试通过。
phoebuswei 2012-08-16
  • 打赏
  • 举报
回复
<script type="text/javascript">
function mytit(id)
{
if (document.getElementById('Label1').innerHTML.indexOf(document.getElementById(id).title)<1)
{
document.getElementById('Label1').innerHTML += document.getElementById(id).title;
}
alert(document.getElementById('Label1').innerHTML.indexOf(document.getElementById(id).title));
}

</script>
</head>
<body>
<input type="text" id="t1p1z11" onclick="mytit(this.id);" runat="server" class="imgbutton" value="0" title="1厅1排11座" readonly="readonly"/></td>
<input type="text" id="t1p1z9" onclick="mytit(this.id);" runat="server" class="imgbutton" value="0" title="1厅1排9座" readonly="readonly"/></td>
<input type="text" id="t1p1z7" onclick="mytit(this.id);" runat="server" class="imgbutton" value="0" title="1厅1排7座" readonly="readonly"/></td>
<label id="Label1" onclick="this.innerHTML=''" > </label>


包退,包邮
baibai620 2012-08-16
  • 打赏
  • 举报
回复
补充下,如果点击2个或2个以上的input type="text",label里面显示的是1厅1排11座,1厅1排9座,1厅1排7座
baibai620 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
HTML code

<td><input type="text" onclick="document.getElementById('Label1').innerHTML=this.title" id="t1p1z11" runat="server" class="imgbutton" value="0" title="1厅1排11座" readonly="readonly"></td>
……
[/Quote]
大哥你这个方法也不行啊,只能显示一个input type="text"的title,点击多个的话只显示最后点击的那个,而且再次点击已经点击过的input type="text",也不会去掉对应的title
wangyizhi58 2012-08-16
  • 打赏
  • 举报
回复
自己再优化下写个方法
<script language="JavaScript" type="text/JavaScript">
var t1p1z11=0;
var t1p1z9=0;
var t1p1z7=0;
document.getElementById('t1p1z11').onclick=function(){
if(t1p1z11%2==0)
{
this.value=this.title;
}
else
{
this.value="0";
}
t1p1z11++;
}
document.getElementById('t1p1z9').onclick=function(){
if(t1p1z9%2==0)
{
this.value=this.title;
}
else
{
this.value="0";
}
t1p1z9++;
}
document.getElementById('t1p1z7').onclick=function(){
if(t1p1z7%2==0)
{
this.value=this.title;
}
else
{
this.value="0";
}
t1p1z7++;
}
</script>
baibai620 2012-08-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
<script type="text/javascript">
$(document).ready(function() {
$("input:text").click(function(){
$("#Label1").html($(this).attr("title"));
})
})
添加一下jquery引用
[/Quote]
好像不行啊,只能显示一个input type="text"的title,点击多个的话只显示最后点击的那个,而且再次点击已经点击过的input type="text",也不会去掉对应的title
孟子E章 2012-08-16
  • 打赏
  • 举报
回复
<td><input type="text" onclick="document.getElementById('Label1').innerHTML=this.title" id="t1p1z11" runat="server" class="imgbutton" value="0" title="1厅1排11座" readonly="readonly"></td>
<td><input type="text" onclick="document.getElementById('Label1').innerHTML=this.title" id="t1p1z9" runat="server" class="imgbutton" value="0" title="1厅1排9座" readonly="readonly"></td>
<td><input type="text" onclick="document.getElementById('Label1').innerHTML=this.title" id="t1p1z7" runat="server" class="imgbutton" value="0" title="1厅1排7座" readonly="readonly"></td>
<label id="Label1" onclick="this.innerHTML=''" ></label>
youbii 2012-08-16
  • 打赏
  • 举报
回复
<script type="text/javascript">
$(document).ready(function() {
$("input:text").click(function(){
$("#Label1").html($(this).attr("title"));
})
})
添加一下jquery引用

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧