Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.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 有没有一种方法可以使用onclick方法填充多个字段_Javascript_Html - Fatal编程技术网

Javascript 有没有一种方法可以使用onclick方法填充多个字段

Javascript 有没有一种方法可以使用onclick方法填充多个字段,javascript,html,Javascript,Html,我有一个图像矩阵。每个图像当前用信息填充特定字段。下面一幅图片的代码 您可以将代码提取到javascript函数中: <a href="#riskrating1" data-toggle="tab"> <img src="components/com_safety101/images/a2.jpg" width="72" height="32" border="0" onclick="populateFields(

我有一个图像矩阵。每个图像当前用信息填充特定字段。下面一幅图片的代码


您可以将代码提取到javascript函数中:

<a href="#riskrating1" data-toggle="tab">
    <img 
        src="components/com_safety101/images/a2.jpg" 
        width="72" height="32" border="0" 
        onclick="populateFields()" />
</a>

<script type="text/javascript">
     function populateFields() {
         document.getElementById('jform_pre_control_risk').value = '10: Undesirable';
         // Populate other fields here
         document.getElementById('other_id').value = 'some other value';
     }
</script>
<a href="#riskrating1" data-toggle="tab">
    <img src="components/com_safety101/images/a2.jpg"
         width="72" height="32" border="0"
         onclick="handleOnClickFor(this)" />
</a>
<script type="text/javascript">
    function handleOnClickFor (element){
        // 'element' would be the DOM Object for the <img> tag,
        // differentiate different images with arguments like this
        // Note that the arguments can be a string, number, object ...
        document.getElementById('jform_pre_control_risk').value = '10: Undesirable'; 
}
</script>

函数populateFields(){
document.getElementById('jform_pre_control_risk')。值='10:不需要';
//在此处填充其他字段
document.getElementById('other_id')。value='some other value';
}

您可以将代码提取到javascript函数中:

<a href="#riskrating1" data-toggle="tab">
    <img 
        src="components/com_safety101/images/a2.jpg" 
        width="72" height="32" border="0" 
        onclick="populateFields()" />
</a>

<script type="text/javascript">
     function populateFields() {
         document.getElementById('jform_pre_control_risk').value = '10: Undesirable';
         // Populate other fields here
         document.getElementById('other_id').value = 'some other value';
     }
</script>
<a href="#riskrating1" data-toggle="tab">
    <img src="components/com_safety101/images/a2.jpg"
         width="72" height="32" border="0"
         onclick="handleOnClickFor(this)" />
</a>
<script type="text/javascript">
    function handleOnClickFor (element){
        // 'element' would be the DOM Object for the <img> tag,
        // differentiate different images with arguments like this
        // Note that the arguments can be a string, number, object ...
        document.getElementById('jform_pre_control_risk').value = '10: Undesirable'; 
}
</script>

函数populateFields(){
document.getElementById('jform_pre_control_risk')。值='10:不需要';
//在此处填充其他字段
document.getElementById('other_id')。value='some other value';
}

单击
onclick
属性中的语句可以包含任意数量的JavaScript语句
如果你想的话,你可以在里面写一个完整的程序——只是看起来很糟糕

更可取的做法是将您希望通过单击
onclick实现的功能放在一个单独的函数中:

<a href="#riskrating1" data-toggle="tab">
    <img 
        src="components/com_safety101/images/a2.jpg" 
        width="72" height="32" border="0" 
        onclick="populateFields()" />
</a>

<script type="text/javascript">
     function populateFields() {
         document.getElementById('jform_pre_control_risk').value = '10: Undesirable';
         // Populate other fields here
         document.getElementById('other_id').value = 'some other value';
     }
</script>
<a href="#riskrating1" data-toggle="tab">
    <img src="components/com_safety101/images/a2.jpg"
         width="72" height="32" border="0"
         onclick="handleOnClickFor(this)" />
</a>
<script type="text/javascript">
    function handleOnClickFor (element){
        // 'element' would be the DOM Object for the <img> tag,
        // differentiate different images with arguments like this
        // Note that the arguments can be a string, number, object ...
        document.getElementById('jform_pre_control_risk').value = '10: Undesirable'; 
}
</script>

并添加一个JavaScript函数:

<a href="#riskrating1" data-toggle="tab">
    <img 
        src="components/com_safety101/images/a2.jpg" 
        width="72" height="32" border="0" 
        onclick="populateFields()" />
</a>

<script type="text/javascript">
     function populateFields() {
         document.getElementById('jform_pre_control_risk').value = '10: Undesirable';
         // Populate other fields here
         document.getElementById('other_id').value = 'some other value';
     }
</script>
<a href="#riskrating1" data-toggle="tab">
    <img src="components/com_safety101/images/a2.jpg"
         width="72" height="32" border="0"
         onclick="handleOnClickFor(this)" />
</a>
<script type="text/javascript">
    function handleOnClickFor (element){
        // 'element' would be the DOM Object for the <img> tag,
        // differentiate different images with arguments like this
        // Note that the arguments can be a string, number, object ...
        document.getElementById('jform_pre_control_risk').value = '10: Undesirable'; 
}
</script>

函数句柄(元素){
//“element”将是标记的DOM对象,
//使用如下参数区分不同的图像
//请注意,参数可以是字符串、数字、对象。。。
document.getElementById('jform_pre_control_risk')。值='10:不需要';
}

单击
onclick
属性中的语句可以包含任意数量的JavaScript语句
如果你想的话,你可以在里面写一个完整的程序——只是看起来很糟糕

更可取的做法是将您希望通过单击
onclick实现的功能放在一个单独的函数中:

<a href="#riskrating1" data-toggle="tab">
    <img 
        src="components/com_safety101/images/a2.jpg" 
        width="72" height="32" border="0" 
        onclick="populateFields()" />
</a>

<script type="text/javascript">
     function populateFields() {
         document.getElementById('jform_pre_control_risk').value = '10: Undesirable';
         // Populate other fields here
         document.getElementById('other_id').value = 'some other value';
     }
</script>
<a href="#riskrating1" data-toggle="tab">
    <img src="components/com_safety101/images/a2.jpg"
         width="72" height="32" border="0"
         onclick="handleOnClickFor(this)" />
</a>
<script type="text/javascript">
    function handleOnClickFor (element){
        // 'element' would be the DOM Object for the <img> tag,
        // differentiate different images with arguments like this
        // Note that the arguments can be a string, number, object ...
        document.getElementById('jform_pre_control_risk').value = '10: Undesirable'; 
}
</script>

并添加一个JavaScript函数:

<a href="#riskrating1" data-toggle="tab">
    <img 
        src="components/com_safety101/images/a2.jpg" 
        width="72" height="32" border="0" 
        onclick="populateFields()" />
</a>

<script type="text/javascript">
     function populateFields() {
         document.getElementById('jform_pre_control_risk').value = '10: Undesirable';
         // Populate other fields here
         document.getElementById('other_id').value = 'some other value';
     }
</script>
<a href="#riskrating1" data-toggle="tab">
    <img src="components/com_safety101/images/a2.jpg"
         width="72" height="32" border="0"
         onclick="handleOnClickFor(this)" />
</a>
<script type="text/javascript">
    function handleOnClickFor (element){
        // 'element' would be the DOM Object for the <img> tag,
        // differentiate different images with arguments like this
        // Note that the arguments can be a string, number, object ...
        document.getElementById('jform_pre_control_risk').value = '10: Undesirable'; 
}
</script>

函数句柄(元素){
//“element”将是标记的DOM对象,
//使用如下参数区分不同的图像
//请注意,参数可以是字符串、数字、对象。。。
document.getElementById('jform_pre_control_risk')。值='10:不需要';
}

我假设必须有一个填充输入元素的模式..我假设必须有一个填充输入元素的模式。。