我正在使用此代码(在我的 .m 文件中)将变量传递到捆绑的 javascript 文件中。
[animalDesciption stringByEvaluatingJavaScriptFromString:@"var myIDcounterVariable = '1'"];
我设置了它,通过按下 UIButton 来更改 UILabel 的值效果很好:
-(IBAction)next:(id)sender {
number++;
[currentNumber setText:[NSString stringWithFormat:@"%d", number]];
}
如何让按钮像我对 Label 所做的那样更改 JavaScript 变量的值?
请原谅我说话结结巴巴!我对这种编程很陌生......
如果我需要提供更多信息,请告诉我。
最佳答案
这就是您所需要的吗?
-(IBAction)next:(id)sender {
number++;
// You want Javascript like this to run:
// myIDCounterVariable = '1'
// but with the current value of 'number' in it.
// Construct the string:
NSString* jsString = [NSString stringWithFormat:@"myIDCounterVariable = '%d'", number];
// and run it
[animalDesciption stringByEvaluatingJavaScriptFromString:jsString];
}
关于javascript - 在 Objective-C 中更改 Javascript 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10157295/