当用户单击按钮时,我必须显示数据库中的联系人编号。 但是当我在javaScript中使用php时,它对我不起作用... 这是HTML
class BurgerForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(BurgerForm, self).__init__(*args, **kwargs)
self.fields['toppings'].widget = forms.CheckboxSelectMultiple()
for field_name in self.fields:
field = self.fields.get(field_name)
if field and isinstance(field , forms.TypedChoiceField):
field.choices = field.choices[1:]
self.fields['extras'].widget = forms.CheckboxSelectMultiple()
class Meta:
model = Burger
fields = ['burger', 'bun', 'toppings', 'sauces', 'extras']
<button name="showNo" id="phone1" onclick="myFunction()"><span>Show Phone No</span></button>
此处是JavaScript
<p id="show">******</p>
还有其他方法可以做到吗?
答案 0 :(得分:2)
尝试一下,p
标签没有值,因此您需要使用innerHTML从中获取数据并进行设置
var hsh = document.getElementById("show").innerHTML;
if(hsh === "******"){
document.getElementById('show').innerHTML = "<?php echo $contact; ?>";
}else{
document.getElementById('show').innerHTML = "<?php echo 'Open Curtain'; ?>";
}