这可能是一个愚蠢的问题,但我无法做到这一点.我可以使用普通的JavaScript更改按钮的功能,但不能使用jQuery.我的目标是一个非常简单的文本调整大小按钮.这个按钮需要两个不同的功能; 一个使文本更大并将click函数更改为另一个函数,另一个函数使文本更小并再次将click函数更改为第一个函数.由于相同的按钮将用于放大和缩小文本sixe,我需要这个工作.我正在研究一个学校项目,我们只需要使用jQuery/jQuery UI进行这项任务.
使用普通的JavaScript,它将是这样的:
var button = document.getElementById('click-button');
button.onclick = firstClick;
function firstClick (){
button.onclick=secondClick;
}
function secondClick(){
button.onclick=firstClick;
}
Run Code Online (Sandbox Code Playgroud)
如何使用jQuery实现相同的功能?
为什么我的TextButtonlibgdx没有响应点击?
我有一个按钮,这个按钮有一个监听器,但它没有响应.该按钮正在显示,但它不会响应鼠标点击.
public MyStage extends Stage {
...
next.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
{
Gdx.app.log(ApothecaryGame.LOG, "Pressed: Next button.");
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
Gdx.app.log( ApothecaryGame.LOG, "Released: Next button.");
super.touchUp( event, x, y, pointer, button );
nextPage();
}
} );
this.addActor(next);
}
Run Code Online (Sandbox Code Playgroud) 我有以下功能:
<script>
function assign()
{
String val="";
String val = document.form1.text1.value;
System.out.println(val);
}
</script>
Run Code Online (Sandbox Code Playgroud)
我试图在按钮单击中调用该功能,如下所示:
<button type="button" onclick="assign()">Display</button>
Run Code Online (Sandbox Code Playgroud)
当我点击按钮时没有任何反应.我希望文本框中的字符串值打印在控制台上.请帮助
我有一个HTML格式的表格,可以将优惠券应用到当前的购物车.我希望用户只需单击APPLY(输入优惠券代码后),然后不刷新页面,就可以运行一些PHP代码,以便计算相应的折扣.
这是我的表格:
<form action="">
<input type="text" name="couponCode">
<input type="submit" value="Apply">
</form>
Run Code Online (Sandbox Code Playgroud)
要运行的PHP:
if (isset($_REQUEST['couponCode']) && $_REQUEST['couponCode']!='')
{
$couponCode = $_REQUEST['couponCode'];
if ($couponCode == "TEST1")
{
$discount=0.2;
}
}
Run Code Online (Sandbox Code Playgroud)
如何使用javascript完成?
该应用程序是一个步进音序器应用程序,具有16个无线电组,每组有8个按钮.除非我使用我创建的清除按钮清除所有放射线组,否则除非一个组选择了一个按钮,否则它可以完美地工作.我想要添加的是一些代码,表示当再次选择所选单选按钮时,它会像切换一样关闭.我尝试使用切换,但随后出现了其他问题.下面是两次尝试,但两个都只是阻止我使用按钮
final RadioGroup radioGroup1 = (RadioGroup)findViewById(R.id.RadioGroup1);
RadioButton D1 = (RadioButton)findViewById(R.id.RadioButtonD1);
Button D1 = (Button)findViewById(R.id.RadioButtonD1);
D1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PdBase.sendFloat("D1", 74);
int selectedTypeId = radioGroup1.getCheckedRadioButtonId();
RadioButton D1 = (RadioButton) findViewById(selectedTypeId);
if(D1 != null) // This will be null if none of the radio buttons are selected
radioGroup1.clearCheck();
PdBase.sendFloat("D1", 0);
}
});
RadioButton lC1 = (RadioButton)findViewById(R.id.RadioButtonlowC1);
lC1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
int selectedTypeId = radioGroup1.getCheckedRadioButtonId();
RadioButton lC1 = (RadioButton) findViewById(R.id.RadioButtonlowC1);
if (selectedTypeId == -1){ …Run Code Online (Sandbox Code Playgroud) 我想创建一个应用程序,我可以单击一个按钮,然后会出现一个新窗口,其中有新的选项/按钮可用.单击按钮后,我已设法创建一个新窗口win2:
private void button1_Click(object sender, RoutedEventArgs e)
{
var win2 = new Window();
win2.Show();
this.Close();
}
Run Code Online (Sandbox Code Playgroud)
现在我如何编辑新窗口.假设我想创建新按钮(名为:blue,green ....),用户可以在其中选择背景颜色.
我尝试将按钮应用于我发现的优雅CSS样式.我需要保持按钮的语义/可访问性原因.但我很好的CSS与按钮元素的原生CSS样式相冲突,并且失去了它.
如何覆盖html按钮元素的自然CSS?
/* CSS works for buttonis, doesn't work for buttons*/
button.btn, buttoni.btn {
...
}
Run Code Online (Sandbox Code Playgroud)
编辑: buttons元素看起来应该与buttonis元素完全相同.
我在WPF中创建了一个模板化按钮:
<ControlTemplate TargetType="{x:Type Button}"
x:Key="BoutonGris">
<Button Foreground="White"
BorderBrush="Transparent"
HorizontalAlignment="Center"
VerticalAlignment="Center"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch">
<Button.Content>
<Border CornerRadius="3"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<ContentPresenter />
<Border.Style>
<Style TargetType="{x:Type Border}">
<Setter Property="Background"
Value="#58585a" />
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="{DynamicResource DegradeCouleurTheme}" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
</Border>
</Button.Content>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
</Button>
</ControlTemplate>
Run Code Online (Sandbox Code Playgroud)
我在我的窗口中使用此按钮:
<Button x:Name="BtnRestoreDefault" Template="{DynamicResource BoutonGris}" Content="Rest. défaut" Height="27" Width="88" Click="Button_Click_RestoreDefault"/>
Run Code Online (Sandbox Code Playgroud)
我的问题是该按钮似乎没有Height ="27"和Width ="88".
这是我在VS2012中的结果:

按钮尺寸合适,但灰色区域没有.我在模板上使用了Stretch关键字,但我没有发现错误.
如果我使用Stretch进行HorizontalAlignment,HorizontalContentAlignment,VerticalAlignment和VerticalContentAlignment,则灰色具有良好的大小,但是,文本内容在左/上!我想要一个中心文字.
有人有想法吗?
非常感谢,
最好的祝福, …
我一直在寻找这个问题的答案很长时间,但仍然没有找到任何东西.我正在使用Tkinter创建一个GUI,除了从不同的小部件接收信息之外,我有两个按钮大致相同.一个按钮用于Entry小部件,另一个按钮用于Listbox小部件.这两个按钮的回调函数很长(约200行),所以我不希望每个按钮都有单独的功能.我在此回调函数的开头有if语句来检查单击了哪个按钮,然后代码将采用相应的值.但我不确定以下代码是否显示正确的方法,因为显然它在我的程序中不能很好地工作.回调函数只能在第一次工作,如果我点击另一个按钮,我将收到一个错误.这是我创建的示例代码,用于说明该想法.请注意,我想检查是否单击了按钮,我不想检查"值"是否存在.请帮忙.
from Tkinter import *
root = Tk()
def DoSomething():
# is this the right way to check which button is clicked?
if button1:
value = user_input.get()
elif button2:
value = choice.get(choice.curselection()[0])
# then more codes that take 'value' as input.
button1 = Button(master,text='Search',command=DoSomething)
button1.pack()
button2 = Button(master,text='Search',command=DoSomething)
button2.pack()
user_input = Entry(master)
user_input.pack()
choice = Listbox(master,selectmode=SINGLE)
choice.pack()
#assume there are items in the listbox, I skipped this portion
root.mainloop()
Run Code Online (Sandbox Code Playgroud) 我有一个自定义UIButton的以下代码:
btnLogin.layer.cornerRadius = 10;
[btnLogin setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bluetint.png"]]];
[btnLogin setAlpha:1];
[btnLogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btnLogin setBackgroundImage:[UIImage imageNamed:@"reallybluetint.png"] forState:UIControlStateHighlighted];
[btnLogin setBackgroundImage:[UIImage imageNamed:@"reallybluetint.png"] forState:UIControlStateSelected];
Run Code Online (Sandbox Code Playgroud)
当我突出显示按钮时,即使它在正常状态下有圆角,它也会变成平方.
有任何想法吗?