简体   繁体   English

Javascript / CSS:动态更改HTML元素的边框颜色

[英]Javascript/CSS: dynamically change border color of HTML element

I have a table rendered from my Laravel installation that displays several properties of my PHP objects, for instance an update interval: 我有一个从Laravel安装中呈现的表,该表显示了我的PHP对象的多个属性,例如更新间隔:

<div class="col-xs-3 text-center">
    <select class="form-control" required id="update_interval" name="update_interval">
        <option value="">update_interval</option>
        <option value="never" selected="selected">never</option>
        <option value="daily">daily</option>
        <option value="weekly">weekly</option>
    </select>
</div>

In the particular case, the 'never' value was set. 在特定情况下,设置为“从不”值。 Next to the settings, a save button is available that allows users to save their settings: 设置旁边有一个保存按钮,允许用户保存其设置:

<div class="col-xs-1 col-sm-1 col-md-1 col-lg-1 col-xl-1 text-center">
    <button type="submit" class="" id="buttonAck16">
        <i class="glyphicon glyphicon-floppy-save"></i>
    </button>
</form>

( i know I could employ ajax for this but my JS/PHP skills are fairly limited....). (我知道我可以为此使用ajax,但是我的JS / PHP技能非常有限。

However, since there can be many rows on page, people might lose track on what was changed. 但是,由于页面上可能有很多行,所以人们可能会失去对更改内容的跟踪。 I would like to color the column entries, for instance changing the the border color, if the selected option differs from the original value. 如果所选选项与原始值不同,我想给列条目上色,例如更改边框颜色。 So if it was set to "never" and an user selects "weekly", that particular item should be highlighted. 因此,如果将其设置为“从不”并且用户选择“每周”,则应突出显示该特定项目。 And if possible, the save button could be highlighted as well. 如果可能的话,保存按钮也可以突出显示。

What kind of Javascript function allows for a continuous check if things are changed? 哪种Javascript函数可以连续检查是否已更改? Anyone? 任何人?

You can use the jQuery .change() event listener: 您可以使用jQuery .change()事件侦听器:

Example: 例:

$( "#update_interval" ).change(function() {
  $(".column-1").css("border-color", "#666");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM