我尝试设置元素的颜色。但还没有成功。这里我也想在点击时运行 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/