【发布时间】:2021-07-26 06:41:04
【问题描述】:
抱歉,有点解释。所以我已经完成了我的 chrome 扩展,并且我的本地存储中已经有一个保存数据,它是 FirstName。所以现在 getElementById 是一个假设当我点击 START 时我正在填写表单的当前页面,这是 button1 希望这些清楚的事情
我还提供了我的 index.html,如果我点击开始,它应该执行 injector.js
index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<style>
html,
body {
height: 200px;
width: 400px;
}
</style>
</head>
<body>
<h1>Adidas ACO</h1>
<h2>Select your choice</h2>
<button><a href="./home.html" target="_blank">Go for Setup</a></button>
<button id="buttonstart"><script src="injector.js"></script>
</script>START</button>
<!-- <br>
<br>
<label for="Title">Title</label>
<input type="text" id="firstnametitle" name="title" size="50" value=""/> -->
<!--<script scr="injector.js"></script>-->
<!--<button onclick="fillforms(fillup)">Start</button>-->
</body>
</html>
injector.js
// Get my button and localstorage data
var button1 = document.getElementById("buttonstart");
var firstName = localStorage.getItem('First Name');
var lastName = localStorage.getItem('Last Name');
var address1 = localStorage.getItem('Address 1');
var address2 = localStorage.getItem('Address 2');
var email = localStorage.getItem('Email');
var phoneNumber = localStorage.getItem('Phone Number');
/// When button is click, it will webscape and fill up
button1.onclick = function(){
var firstName = localStorage.getItem('First Name');
var field1 = document.getElementsByClassName("shippingAddress-firstName");
fillField(field1, firstName);
console.log(field1)
console.log(firstName)
}
function fillField(field1, value){
if(field1){
field1.value = value;
}
}
【问题讨论】:
-
好像 field1 (
input[id="shippingAddress-firstName"]) 不存在。 -
我第二个@SimoneRossaini,为什么不让选择器只是#shippingAddress-firstName 而不是'input[id=..]'?
-
真 :) @SanthosRamalingam
-
好吧,伙计们,因为我正在做一些测试,但仍然无法正常工作
-
标签: javascript html web-scraping google-chrome-extension console