我想要一些jQuery代码,当我单击文本框时,它可以让我找到控件的标签……因此,在我的HTML中,我有以下内容:
<label id="ctl00_WebFormBody_lblProductMarkup"  for="ctl00_WebFormBody_txtPriceAdjustment">This Is My Label Value</label>
<input type="text" style="width:29px;" onclick="alert('label value here');" title="Here is a title" id="ctl00_WebFormBody_txtPriceAdjustment" maxlength="3" name="ctl00$WebFormBody$txtPriceAdjustment">所以,当我点击我的文本框时,我想(举个例子)做一个警告…使用我的标签中的文本-所以在本例中它会提示"This is my label value“
希望这是有意义的:)
发布于 2011-09-17 21:29:07
使用javascript执行此操作
<script type="text/javascript">
function displayMessage()
{
alert(document.getElementById("ctl00_WebFormBody_lblProductMarkup").innerHTML);
}
</script>
<label id="ctl00_WebFormBody_lblProductMarkup"  for="ctl00_WebFormBody_txtPriceAdjustment">This Is My Label Value</label>
<input type="text" style="width:29px;" onclick="displayMessage()" title="Here is a title" id="ctl00_WebFormBody_txtPriceAdjustment" maxlength="3" name="ctl00$WebFormBody$txtPriceAdjustment">https://stackoverflow.com/questions/7455049
复制相似问题