以表格形式(用PHP制造)获取文本字段的标签(使用Javascript) [英] Getting the label (in Javascript) of a text field in a form (made in PHP)

查看:63
本文介绍了以表格形式(用PHP制造)获取文本字段的标签(使用Javascript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用一些JavaScript来获取表单的字段值,并检查它们是否为空:

if(document.getElementById(''FIELD'').value=='''')

然后,我有兴趣将关联标签添加到该文本FIELD ...

它应该类似于:

document.getElementById(''FIELD'').label



在PHP方面,我已经做到了:

 $ str.='<   td     ft1 " <     for   =" 字段"  ACCESSKEY   没有" ">>  <   b    样式  ="  >  *这是我想在JAVASCRIPT中阅读的标签文本<  /b  >  <  > ';
$ str.='<   td      ="  >  <  选择 名称   FIELD "  id    FIELD" 解决方案

str.='< =" ft1" < LABEL FIELD" ACCESSKEY =" > < b 样式 =" 颜色:#ff6d00" < /b > < /td > ';

str.='< td class ft2" > < 选择 名称 =" 字段" id =" > ' ;



我无法使其正常运行,实际上我不知道在哪里搜索...

这里有人知道吗?

预先谢谢您.


aisin Tajadod注释的第一部分很好-实现此目的最简单的方法是为标签提供一个ID.但是,尽管我强烈建议您在使用jQuery之前先考虑使用jQuery进行此操作,但是如果您想在老派上使用jQuery,则应使用类似以下的内容:

 


Hello all,

I''m using some javascript to get the field values of a form and to check if they are empty or not:

if(document.getElementById(''FIELD'').value=='''')

Then I''m interested on getting the associated label to that text FIELD...

It should be something like:

document.getElementById(''FIELD'').label



In the PHP side I''ve done this:

$str .= '<td class="ft1"><LABEL for="FIELD" ACCESSKEY="none" ><b style="color:#ff6d00">* THIS IS THE LABEL TEXT I WANT TO READ IN JAVASCRIPT</b></td>';
$str .= '<td class="ft2"><select name="FIELD" id="FIELD">';



I''ve not been able to get it working and truly I don''t know where to search...

Anyone here knows it?

Thank you in advance.

解决方案

str .= '<td class="ft1"><LABEL for="FIELD" ACCESSKEY="none" ><b style="color:#ff6d00">* THIS IS THE LABEL TEXT I WANT TO READ IN JAVASCRIPT</b></td>';


str .= '<td class="ft2"><select name="FIELD" id="FIELD">';



I''ve not been able to get it working and truly I don''t know where to search...

Anyone here knows it?

Thank you in advance.


The first part of aidin Tajadod comment is good - the easiest way for you to do this is by giving your label an Id. However, though I would strongly advise you look at doing this using jQuery before you go too far with it, if you want to do it old school you should use something like this:


这篇关于以表格形式(用PHP制造)获取文本字段的标签(使用Javascript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆