Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态更改跨类_Javascript_Html_Forms_Validation - Fatal编程技术网

Javascript 动态更改跨类

Javascript 动态更改跨类,javascript,html,forms,validation,Javascript,Html,Forms,Validation,如果某个元素为null,我想在该元素旁边打印错误消息 我知道要补充一点 <div> tag 标签 在该元素之后打印它。但是我没有编辑权限来编辑代码 所以,我想更改元素标签的span类,它将highlist列为缺少的字段 我的页面就像 <td><span class="fl">Country</span></td> <td class="abcdef" style="...." id="Country"> <

如果某个元素为null,我想在该元素旁边打印错误消息

我知道要补充一点

<div> tag 
标签
在该元素之后打印它。但是我没有编辑权限来编辑代码

所以,我想更改元素标签的span类,它将highlist列为缺少的字段

我的页面就像

 <td><span class="fl">Country</span></td>
 <td class="abcdef" style="...." id="Country">
 <select>
 <option></option>
 </select>
 ....
国家
....
现在我想将spanc类“f1”更改为“requiredText”。 但问题是许多标签都被

  '<span clas="f1">' 
   and 
  '</span>'.
“”
及
''.
有什么方法可以将它与ID Country的前面元素标识并关联起来吗?

试试这个

$('.f1').addClass('myclass).removeClass('f1')
$('td .f1').removeClass('f1').addClass('myclass');
试试这个

$(".f1").each(function(x, span) {
        var text = $(span).html();
        if(text == '')
             $(span).addClass('requiredText').removeClass('f1');
    });

我在这里没有看到jQuery标记。因此,如果您想在没有jQuery的情况下执行此操作,可以这样做:

document.getElementById('Country')     // get the table cell with id="Country"
        .previousElementSibling        // get its previous sibling so the td with the span
        .children[0]                   // get the span you want
        .className = "requiredText";   // overwrite it's class name

你想换哪一个班??只有一个国家作为文本??