对不起,我的英语不好。
我有一种形式,当通过各种按钮调用时,应隐藏一些字段。
以下是按钮:
<a data-target="#call">Button 1</a>
<a data-target="#call">Button 2</a>
这是表格:
<div id="call">
<form>
<div class="pole1">Field 1</div>
<div class="pole2">Field 2</div>
</form>
</div>
一个表单只能有一个ID,在我看来,这是一个“呼叫”。
如何在单击“按钮1”时仅显示“字段1”? 当您单击“按钮2”时仅显示“字段2”时,该怎么做?
答案 0 :(得分:0)
请尝试这个
io.on('connection', (socket) => {
//create canChannel with socketcan(node-can)
var channel = can.createRawChannel('vcan0', true);
//emit messagees to the *can message* listening to the canChannel
socket.emit('can message', channel.addListener('onMessage', (data) => {
io.emit('can message', data);
}));
channel.start();
//disconnect
socket.on('disconnected', (socket) => {
console.log('socket disconnected');
});
这是表格:
constructor() {
this.socket = io();
this.socket.on('can message', (msg) => {
console.log('data', msg);
});
}
javascript代码:
<a data-target="#call" onclick="show('id1');">Button 1</a>
<a data-target="#call" onclick="show('id2');">Button 2</a>
答案 1 :(得分:0)
尝试一下。
<!DOCTYPE html>
<html>
<body>
<a href="#" onclick='myFunction1()'>Button 1</a>
<a href="#" onclick="myFunction2()">Button 2</a>
<div id="call">
<form>
<div class="pole1" id="Field1Id">Field 1</div>
<div class="pole2" id="Field2Id">Field 2</div>
</form>
</div>
<p id="demo"></p>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script>
function myFunction1() {
$("#Field1Id").show();
$("#Field2Id").hide();
}
function myFunction2() {
$("#Field1Id").hide();
$("#Field2Id").show();
}
</script>
</body>
</html>