开发者

Recommended way to obtain user input in chrome extension?

开发者 https://www.devze.com 2023-02-08 23:46 出处:网络
I have a settings page in my Chrome extension and I am wondering what is the recommended (\"best\") way of obtaining user input. In my particular case, I need to present a set of combo choices along w

I have a settings page in my Chrome extension and I am wondering what is the recommended ("best") way of obtaining user input. In my particular case, I need to present a set of combo choices along with a button. When the button is clicked, a javascript function should be executed. My understanding is that if I use a , this will post a request which I don't want (it causes the page to flash & reload). I want all of this to be client-side. Here is what I have so far (below). How can this be changed? Thanks in advance.

<form>
开发者_运维技巧    <input type="radio" name="format" value="format1"/>(xxx) xxx-xxxx<br/>
    <input type="radio" name="format" value="format2"/>xxx-xxx-xxxx<br/>
    <input type="radio" name="format" value="format3"/>xxx.xxx.xxxx<br/>
    <input type="submit" value="Convert"/>
</form>


Bob, well, you can do everything in JavaScript. And since this is a Chrome Extension, feel free to use just HTML5.

<section>
  <input type="radio" name="format" value="format1"/>(xxx) xxx-xxxx<br/>
  <input type="radio" name="format" value="format2"/>xxx-xxx-xxxx<br/>
  <input type="radio" name="format" value="format3"/>xxx.xxx.xxxx<br/>
  <button id="btnConvert">Convert</button>
  <script>
  document.querySelector('#btnConvert').addEventListener('click', function(e) {
    var format = document.querySelector('input[type="radio"]:checked');
    alert( format.value);
  }, false);
  </script>
</section>

Hope that helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消