<a href="#" onclick="return prompt('Enter title for new player:') != ''">Duplicate</a>
<a href="#" onclick="return prompt('Enter title for new player:') != null">Duplicate</a>
编辑:(我的示例稍微复杂一些)
我使用php进行翻译:
<a href="#" class="btn" onclick="return prompt('<?php printf(esc_attr__('Enter title for new player:', 'domain'))?>') || false"<?php _e('Duplicate', 'domain'); ?></a>
我需要获得成功提示的标题(以便我可以将其与get一起发送)
我试过:
$('.btn').on('click', function(){
var btn = $(this), val = btn.val();
if(val !== null || val != ''){
console.log(val)
}
});
<a href="#" onclick="getName()">Enter title</a>
<script>
function getName() {
var name = prompt('Enter name for new player:');
if(name == null || name == "") {
getName();
}
return name;
}
</script>