将混合字符串和int参数传递给javascript

时间:2016-04-13 12:09:43

标签: javascript php parameters

我已经环顾四周,似乎无法找到合适的解决方案,所以这就是要求。

我正在构建一个系统,该系统从主页面获取数据并将其加载到模态样式窗口中以进行快速数据处理。我有一个javascript函数传递4个状态参数,而其中3个将始终是整数,其中一个可以是整数或字符串。

如果所有4个参数都是整数,则该函数有效,但在传递字符串时失败。

function passJob(jobid,equipid,status,location) {

var a = document.getElementById('jobnumber');
var b = document.getElementById('equipid');
var c = document.getElementById('status');
var d = document.getElementById('location');
  a.value = jobid;
  b.value = equipid;  
  c.value = status;  
  d.value = location;  
}

PHP

<a href='#' onclick='passJob($sr,$eid,$ss,$sl);'>Modify Job</a>

$ sr,$ ss和$ sl将始终为数字,$ eid将为整数,或者以M开头,然后在其后面加上数字的字符串。

我尝试在变量,变量周围,函数内部添加引号,但没有运气:(

4 个答案:

答案 0 :(得分:1)

如果你不知道它们是什么,你需要传递为字符串 - 同时确保你没有嵌套相同类型的引用:

from selenium import webdriver
from selenium.webdriver.support import ui
from selenium.webdriver.common.keys import Keys
def page_is_loaded(driver):
    return driver.find_element_by_tag_name("body") != None
driver = webdriver.Firefox()
driver.get("http://blabla.htm")
wait = ui.WebDriverWait(driver, 10)
wait.until(page_is_loaded)
email_field = driver.find_element_by_id("sap-user")
email_field.send_keys("foo")
password_field = driver.find_element_by_id("sap-password")
password_field.send_keys("blabla")
password_field.send_keys(Keys.RETURN)
page_is_loaded()

答案 1 :(得分:0)

用引号括起来。这样可以随时将其视为字符串,以避免任何潜在的JavaScript解析错误。

04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime: FATAL EXCEPTION: main
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime: Process: app.tvtracker.kls.tvtracker, PID: 3875
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime: java.lang.OutOfMemoryError
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.content.res.Resources.loadDrawable(Resources.java:2110)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.content.res.Resources.getDrawable(Resources.java:700)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.widget.ImageView.resolveUri(ImageView.java:638)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.widget.ImageView.setImageResource(ImageView.java:367)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at app.tvtracker.kls.tvtracker.ImageAdapter.getView(ImageAdapter.java:43)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.widget.AbsListView.obtainView(AbsListView.java:2255)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.widget.GridView.makeAndAddView(GridView.java:1345)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.widget.GridView.makeRow(GridView.java:345)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.widget.GridView.fillDown(GridView.java:287)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.widget.GridView.fillGap(GridView.java:247)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5143)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.widget.AbsListView.onGenericMotionEvent(AbsListView.java:3811)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.View.dispatchGenericMotionEventInternal(View.java:7801)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.View.dispatchGenericMotionEvent(View.java:7782)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:1777)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.View.dispatchGenericMotionEvent(View.java:7775)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:1777)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.View.dispatchGenericMotionEvent(View.java:7775)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:1777)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.View.dispatchGenericMotionEvent(View.java:7775)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:1777)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.View.dispatchGenericMotionEvent(View.java:7775)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:1777)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.View.dispatchGenericMotionEvent(View.java:7775)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchTransformedGenericPointerEvent(ViewGroup.java:1824)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewGroup.dispatchGenericPointerEvent(ViewGroup.java:1777)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.View.dispatchGenericMotionEvent(View.java:7775)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchGenericMotionEvent(PhoneWindow.java:2076)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at com.android.internal.policy.impl.PhoneWindow.superDispatchGenericMotionEvent(PhoneWindow.java:1525)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.app.Activity.dispatchGenericMotionEvent(Activity.java:2494)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.support.v7.internal.view.WindowCallbackWrapper.dispatchGenericMotionEvent(WindowCallbackWrapper.java:70)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchGenericMotionEvent(PhoneWindow.java:2030)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.View.dispatchPointerEvent(View.java:7888)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:     at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
04-13 08:21:36.583 3875-3875/app.tvtracker.kls.tvtracker E/AndroidRuntime:  at android.vi
04-13 08:21:39.051 3875-3875/? I/Process: Sending signal. PID: 3875 SIG: 9

答案 2 :(得分:0)

这是因为您没有使用Javascript表示法正确编码变量。尝试:

echo "<a href='#' onclick='passJob(".json_encode($sr).",".json_encode($eid).",".json_encode($ss).",".json_encode($sl).");'>Modify Job</a>";

答案 3 :(得分:0)

如下所示

<a href="#" onclick="passJob($sr, '$eid', $ss, $sl);">Modify Job</a>