javascript - js - 在点击问题上设置元素颜色

标签 javascript

我尝试设置元素的颜色。但还没有成功。这里我也想在点击时运行 2 个函数(addXXX,setcolor)。

<div id="tweet">'.$tweet['text'].'</div>        
<input type="radio" name="pos" value="POS" 
       onclick="addPOS(this.previousElementSibling.innerHTML+\' \');
       $(#tweet).css(\'background-color\', \'red\');">
  <span class="label label-success">Pos</span>
</input>
<input type="radio" name="pos" value="NON" 
       onclick="addNON(this.previousElementSibling.previousElementSibling.previousElementSibling.innerHTML+\' \');
       $(#tweet).css(\'background-color\', \'blue\');">
  <span class="label label-warning">Non</span></input>
<input type="radio" name="pos" value="NEG" 
         onclick="addNEG(this.previousElementSibling.previousElementSibling.previousElementSibling.previousElementSibling.previousElementSibling.innerHTML+\' \');
         $(#tweet).css(\'background-color\', \'yellow\');">
  <span class="label label-important">Neg</span>
</input>';

最佳答案

使用 Jquery,

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <div id="tweet">test</div>
 <input type="radio" name="pos" value="POS" onclick="$('#tweet').css('background-color', 'yellow');">

如果使用普通的 JavaScript,

<div id="tweet">test</div>
<input type="radio" name="pos" value="POS" onclick="document.getElementById('tweet').style.background = 'yellow'">

关于javascript - js - 在点击问题上设置元素颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18029757/

相关文章:

javascript - 恢复或暂停cordova事件后如何解决?

javascript - 在我的案例中如何连接到 elasticache?

javascript - 带对象的 Knockout/Typescript ko.observables

javascript - jQuery UI - 未捕获的类型错误 : Object function (a, b){return new e.fn.init(a,b,h)} 没有方法 'dialog'

javascript - jquery ajax 调用后重新加载页面

php - 使用 mysqli_query 进行 json 表单验证

javascript - 打印iframe内容

javascript - 它与 Javascript 不同,将 JSON 获取为 "text/html"和 "file"?

javascript - 为什么我输入的数据长度只有1个符号却是0?

javascript - 通过前端而不是 http 与后端通信