为什么onclick方法没有返回false就无法工作.当我尝试使用它而不返回false它显示答案然后值消失..
<form id="form1" method="POST">
<table style="border:1px solid black">
<tr>
<td>First Number</td>
<td>
<input type="text" id="first">
</td>
</tr>
<tr>
<td>Second Number</td>
<td>
<input type="text" id="second">
</td>
</tr>
<tr>
<td>Result</td>
<td>
<input type="text" id="result">
</td>
</tr>
<td>
<button id="btn" value="Add" onClick="addNumbers();return false;">Add</button>
</td>
</table>
</form>
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
function addNumbers() {
var firstNumber = document.getElementById('first').value;
var secondNumber = document.getElementById('second').value;
document.getElementById('result').value = firstNumber + secondNumber;
}
Run Code Online (Sandbox Code Playgroud)
我想只删除已检查的div元素.我的脚本删除所有动态创建的div元素.我做错了什么?
HTML:
<div class="container">
<form>
<p>Title:</p>
<input type="text" id="title" />
<p>Link:</p>
<input type="text" id="link" />
</form>
<br>
<button class="btn btn-success">Add</button>
<button class="btn btn-danger">Delete</button>
</div>
<div class="content" style="margin-top:50px">
<div class="content_wrapper"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$(function () {
$(".btn-success").click(function () {
var title_val = $("#title").val();
var link_val = $("#link").val();
$(".content").append('<div class="content_wrapper"><div class="col-xs-6 col-md-4"><ol class="breadcrumb"><h4>' + title_val + '</h4><input type="checkbox" class="checkbox"></ol><a href="http://' + link_val + '" class="thumbnail"></a></div></div>');
});
$(document).on("click", ".btn-danger", function () {
if ($(".checkbox").is(":checked")) {
$(".content_wrapper").remove();
}
});
});
Run Code Online (Sandbox Code Playgroud)
我需要设置从新行输入的数组中的每个元素,我想做它喜欢这个连接("\n") - 对我来说不起作用.我怎么能正确地做到这一点
这是我的代码
var inp = document.getElementById("inp");
var btn = document.querySelector(".btn");
var list = document.querySelector('#list');
var arr = [];
btn.addEventListener('click', function(str) {
var valInp = inp.value;
arr.push(valInp);
inp.value = "";
list.innerHTML = arr.join(" ");
});
Run Code Online (Sandbox Code Playgroud)
我刚开始学习 Python 并面临这个问题。Trued 从亚马逊解析价格并将其打印到控制台。
这是我的代码:
import requests, bs4
def getAmazonPrice(productUrl):
res = requests.get(productUrl)
res.raise_for_status()
soup = bs4.BeautifulSoup(res.text, 'html.parser')
elems = soup.select('#addToCart > a > h5 > div > div.a-column.a-span7.a-text-right.a-span-last > span.a-size-medium.a-color-price.header-price')
return elems[0].text.strip()
price = getAmazonPrice('http://www.amazon.com/Automate-Boring-Stuff-Python-Programming/dp/1593275994/ref=sr_1_2?ie=UTF8&qid=1460386052&sr=8-2&keywords=python+book')
print('The price is ' + price)
Run Code Online (Sandbox Code Playgroud)
错误信息:
回溯(最近一次调用):文件“D:/Code/Python/Basic/webBrowser-Module.py”,第 37 行,在 price = getAmazonPrice(' http://www.amazon.com/Automate-Boring-Stuff -Python-Programming/dp/1593275994/ref=sr_1_2?ie=UTF8&qid=1460386052&sr=8-2&keywords=python+book ') 文件“D:/Code/Python/Basic/webBrowser-Module.py”,第 30 行,在getAmazonPrice res.raise_for_status() 文件“C:\Python33\lib\requests\models.py”,第 844 行,在 raise_for_status 中引发 HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError:503 服务器错误:服务不可用 url : http://www.amazon.com/Automate-Boring-Stuff-Python-Programming/dp/1593275994/ref=sr_1_2?ie=UTF8&qid=1460386052&sr=8-2&keywords=python+book
进程以退出代码 1 结束
如何以随机顺序设置包含数组中所有值的textarea的值?我目前有2个问题:
这是我的代码
var area = document.getElementById('area');
var arr =['www.google.com','www.bing.com','www.yahoo.com','www.codecademy.com','twitter.com'
];
var rand = arr[Math.floor(Math.random()*arr.length)];
for(var i in arr) {
area.value = arr[i];
}
Run Code Online (Sandbox Code Playgroud)