简体   繁体   English

OnSubmit更改DOM元素的值和属性

[英]OnSubmit change DOM elements values and attributes

I have have two text input elements: 我有两个文本输入元素:

<input type="text" id="Title"/> 
<input type="text" id="URL"/> 

One dropdown menu and a submit button. 一个下拉菜单和一个提交按钮。 The select drop down menu has several options whose value equals the ID of an element in the page. select下拉菜单有几个选项,其值等于页面中元素的ID。

If you click the submit button it will change/fill values in the div element whose ID is selected in the dropdown menu. 如果单击提交按钮,它将更改/填充在下拉菜单中选择其ID的div元素中的值。

<img src="https://www.google.com/s2/favicons?domain=$URL" alt="Icon" title="icon">
<a href="$URL" title="$TITLE"> $TITLE </a><br />

into the div with the ID selected in the drop-down menu. 进入div,并在下拉菜单中选择ID。

Example

Title input value = "Google" 标题输入值=“ Google”
URL input value = " http://www.google.com " URL输入值=“ http://www.google.com
Select option ID = "Search_Engines" 选择选项ID =“ Search_Engines”

And you'd press "Submit" 然后您按“提交”

Then that'd permanently write into the element with the id Search_Engines 然后将其永久写入ID为Search_Engines的元素中

<img src="https://www.google.com/s2/favicons?domain=http://www.google.com" alt="Icon" title="icon">  
<a href="http://www.google.com" title="Google"> Google </a><br />

Is there anyway this can be achieved? 无论如何,这可以实现吗?

Javascript: Javascript:

<script>
        function change(){
           var Title = document.getElementById('Title').value;
           var URL = document.getElementById('URL').value;
           var Element = document.getElementById('Element').value;
           var div = document.getElementById(Element);
           div.innerHTML = Title + " " + URL;
           return false;
        }
    </script>

And html Form 和html表单

<form>
        <input type="text" name="Title" id="Title"><br />
        <input type="text" name="URL" id="URL"><br />

        <select name="Element" size="1" id="Element">
            <option>1</option>
            <option>2</option>
        </select>
        <input type="submit" name="submit" value="submit" onclick="return change()">
    </form>
    <div id="1">text</div>
    <div id="2">text</div>

Guess there are better solutions but works. 猜想有更好的解决方案,但可以。

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

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