所以我有一个在线商店,我有一个调用名为var poster_image_path = pswp.currItem.html.split('"')[1]
的函数的按钮,但在Javascript中这个函数有purchase()
。所以,您可以轻松地在onclick函数purchase(name, amount)
中输入名称,但我的问题是我可以如何计算金额?金额是从onclick="purchase('milk')
元素中选择的。
我也创建了一些JSFiddle,所以你可以看看:https://jsfiddle.net/w2bk9hw8/
答案 0 :(得分:1)
使用jquery你可以做到这一点;
<button class="button" onclick="payment('milk', $('select').val())">$1.85</button>
答案 1 :(得分:1)
JQuery less解决方案可能是:
declare
l_alter_stmt_1 varchar2(4000);
l_alter_stmt_2 varchar2(4000);
l_adjust_stmt varchar2(4000);
l_nextval number;
begin
for r in (select * from user_sequences) loop
l_adjust_stmt := 'select "' || r.sequence_name || '".nextval from dual';
execute immediate l_adjust_stmt into l_nextval;
l_alter_stmt_1 := 'ALTER SEQUENCE "' || r.sequence_name || '"'
|| ' INCREMENT BY '|| (r.min_value - l_nextval);
l_alter_stmt_2 := 'ALTER SEQUENCE "' || r.sequence_name || '"'
|| ' INCREMENT BY ' || r.increment_by;
dbms_output.put_line(l_alter_stmt_1);
-- execute immediate r.alter_stmt_1;
dbms_output.put_line(l_adjust_stmt);
-- execute immediate l_adjust_stmt into l_nextval;
dbms_output.put_line(l_alter_stmt_2);
-- execute immediate l_alter_stmt_2;
end loop;
end;
/
PL/SQL procedure successfully completed.
ALTER SEQUENCE "SUPPLIER_SEQUENCE" INCREMENT BY -101
select "SUPPLIER_SEQUENCE".nextval from dual
ALTER SEQUENCE "SUPPLIER_SEQUENCE" INCREMENT BY 1
答案 2 :(得分:0)
没有什么奇怪的。你只需编写函数并调用它。
function purchase(product){
var select = document.querySelector("select#id");
alert('You have ordered '+select.value+' unit(s) of ' + product);
}
<select id="id">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<button onclick="purchase('milk')">test</button>
答案 3 :(得分:0)
function payment(name, amount) {
console.log(amount,name);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<button class="button" onclick="payment('milk', $('#quantity').val())">$1.85</button>
找到Fiddle
如果适合您,请标记
答案 4 :(得分:0)
这应该有用(纯javascript):
<select id="amount">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<button class="button" onclick="order('milk', getAmount)">$1.85</button>
<script>
function order(name, amount) {
alert(name);
alert(getAmount());
}
function getAmount(){
return document.getElementById('amount').value
}
</script>
答案 5 :(得分:0)
选择一个ID,然后它非常简单:
<select id="target-select">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<button class="button" onclick="payment('milk', document.getElementById('target-select').value)">$1.85</button>
<script>
function payment(name, amount) {
alert(name);
alert(amount);
}
</script>
&#13;
答案 6 :(得分:0)
考虑到发布时的答案都在Jquery中,我在JS中提供答案。
为每个选项提供值
我已经为选择添加了值,因为它们是为每个选择选项分配哪个号码所必需的。
<option value="2">2</option>
获取所选选项的值
要获取选择按钮的值,您可以使用document.getElementById(&#39; sel&#39;)访问该按钮,并使用.value运算符来获取所选选项。
document.getElementById('sel').value)
您可以在下面找到该片段。
function order(name, amount) {
alert(name);
alert(amount);
}
&#13;
<select id="sel">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<button class="button" onclick="order('milk',document.getElementById('sel').value)">$1.85</button>
&#13;
答案 7 :(得分:0)
你可以做这样的事情:
$('#myselect').on('click', function(){
var value = $('#myselect option:selected').val();
$('button').html(value +'$');
})
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<select id="myselect">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<button class="button">$1.85</button>
&#13;
答案 8 :(得分:0)
如果您在页面上有多个按钮...
$('button').on('click', function() {
payment('milk', $(this).attr("value"));
});