如何将div id转换成php变量?

时间:2016-07-07 10:12:25

标签: javascript php jquery html

如何在提交表单后将此id转换为PHP变量?我需要将总值传递给PHP变量。请帮我解决这个问题。

<div class="table-responsive">
    <table class="table table-bordered">
        <tr>        
            <th>Total Price</th>
        </tr>
        <tr>                 
            <td>
                <input class="form-control1" type='text' id='txt_totalprice' name='txt_totalprice[]'/> 
            </td>
        </tr>
    </table>     
</div>

Total: <div id="totalvalue">0</div>  

这是脚本

<script type='text/javascript'>
    $('#totalvalue').click(function() {
        $.post("package.php", { 
            id: $(this).attr('id') 
        }, function(response) {
            alert(response);
        });
    });
</script>     

2 个答案:

答案 0 :(得分:5)

您希望div标签之间的值,而不是ID,是否正确?

改变这个:

id: $(this).attr('id')

对此:

id: $(this).text()

如果要在页面上显示值,请执行以下操作:

创建一个空div:

<div id="saved-value"></div>

将它放在页面上任意位置。

然后改变你的jQuery:

}, function(response) {
    $('#saved-value').html(response);
});

答案 1 :(得分:1)

这是你在package.php页面上获取id值的方法。

Software.UI.ViewModel.dll!ProgramEditor.ViewModel.LoadingTileViewModel.ExecuteViewLoadedEventHandlerCommand(object parameter) Line 168  C#
Software.UI.ViewModel.dll!ProgramEditor.ViewModel.LoadingTileViewModel.get_ViewLoadedEventHandlerCommand.AnonymousMethod__50_0(object i) Line 184   C#
[Native to Managed Transition]  
[Managed to Native Transition]  
GalaSoft.MvvmLight.dll!GalaSoft.MvvmLight.Helpers.WeakAction<System.__Canon>.Execute(System.__Canon parameter)  Unknown
GalaSoft.MvvmLight.dll!GalaSoft.MvvmLight.Command.RelayCommand<object>.Execute(object parameter)    Unknown
System.Windows.Interactivity.dll!System.Windows.Interactivity.InvokeCommandAction.Invoke(object parameter)  Unknown
System.Windows.Interactivity.dll!System.Windows.Interactivity.TriggerBase.InvokeActions(object parameter)   Unknown
System.Windows.Interactivity.dll!System.Windows.Interactivity.EventTriggerBase.OnEvent(System.EventArgs eventArgs)  Unknown
System.Windows.Interactivity.dll!System.Windows.Interactivity.EventTriggerBase.OnEventImpl(object sender, System.EventArgs eventArgs)   Unknown
PresentationCore.dll!System.Windows.RoutedEventHandlerInfo.InvokeHandler(object target, System.Windows.RoutedEventArgs routedEventArgs) Unknown
PresentationCore.dll!System.Windows.EventRoute.InvokeHandlersImpl(object source, System.Windows.RoutedEventArgs args, bool reRaised)    Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject sender, System.Windows.RoutedEventArgs args)   Unknown
PresentationCore.dll!System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs e)  Unknown
PresentationFramework.dll!System.Windows.BroadcastEventHelper.BroadcastEvent(System.Windows.DependencyObject root, System.Windows.RoutedEvent routedEvent)  Unknown
PresentationFramework.dll!System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(object root) Unknown
PresentationCore.dll!MS.Internal.LoadedOrUnloadedOperation.DoWork() Unknown
PresentationCore.dll!System.Windows.Media.MediaContext.FireLoadedPendingCallbacks() Unknown
PresentationCore.dll!System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()    Unknown
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandlerCore(object resizedCompositionTarget)    Unknown
PresentationCore.dll!System.Windows.Media.MediaContext.RenderMessageHandler(object resizedCompositionTarget)    Unknown
PresentationCore.dll!System.Windows.Media.MediaContext.Resize(System.Windows.Media.ICompositionTarget resizedCompositionTarget) Unknown
PresentationCore.dll!System.Windows.Interop.HwndTarget.OnResize()   Unknown
PresentationCore.dll!System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage msg, System.IntPtr wparam, System.IntPtr lparam) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.HwndTargetFilterMessage(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)   Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)  Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)   Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)  Unknown
[Native to Managed Transition]  
user32.dll!74d862fa()   Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]    
user32.dll!74d86d3a()   Unknown
user32.dll!74d86ded()   Unknown
user32.dll!74d86e4c()   Unknown
ntdll.dll!773a011a()    Unknown
user32.dll!74d872c1()   Unknown
user32.dll!74dad4ff()   Unknown
user32.dll!74d862fa()   Unknown
user32.dll!74d86d3a()   Unknown
user32.dll!74d90d37()   Unknown
user32.dll!74d90d5d()   Unknown
WindowsBase.ni.dll!6b4a6e70()   Unknown
[Managed to Native Transition]  
WindowsBase.dll!MS.Win32.HwndSubclass.DefWndProcWrapper(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)    Unknown
[Native to Managed Transition]  
user32.dll!74d862fa()   Unknown
user32.dll!74d86d3a()   Unknown
user32.dll!74d90d37()   Unknown
user32.dll!74d90d5d()   Unknown
WindowsBase.ni.dll!6b4ced1a()   Unknown
[Managed to Native Transition]  
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)  Unknown
[Native to Managed Transition]  
user32.dll!74d862fa()   Unknown
user32.dll!74d86d3a()   Unknown
user32.dll!74d86ded()   Unknown
user32.dll!74d86ded()   Unknown
user32.dll!74d88fb7()   Unknown
ntdll.dll!773a011a()    Unknown
user32.dll!74d92832()   Unknown
user32.dll!74d92802()   Unknown
user32.dll!74d9289a()   Unknown
[Managed to Native Transition]  
MahApps.Metro.dll!Standard.NativeMethods.SetWindowRgn(System.IntPtr hWnd, System.IntPtr hRgn, bool bRedraw) Unknown
MahApps.Metro.dll!Microsoft.Windows.Shell.WindowChromeWorker._SetRoundingRegion(Standard.WINDOWPOS? wp) Unknown
MahApps.Metro.dll!Microsoft.Windows.Shell.WindowChromeWorker._UpdateFrameState(bool force)  Unknown
MahApps.Metro.dll!Microsoft.Windows.Shell.WindowChromeWorker._ApplyNewCustomChrome()    Unknown
MahApps.Metro.dll!Microsoft.Windows.Shell.WindowChromeWorker._WindowSourceInitialized(object sender, System.EventArgs e)    Unknown
PresentationFramework.dll!System.Windows.Window.OnSourceInitialized(System.EventArgs e) Unknown
PresentationFramework.dll!System.Windows.Window.CreateSourceWindow(bool duringShow) Unknown
PresentationFramework.dll!System.Windows.Window.CreateSourceWindowDuringShow()  Unknown
PresentationFramework.dll!System.Windows.Window.SafeCreateWindowDuringShow()    Unknown
PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox)   Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)  Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl()   Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(object state)  Unknown
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj)   Unknown
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx)   Unknown
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state)  Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke()   Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue()  Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)  Unknown
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs)  Unknown
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs)   Unknown
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam)  Unknown
[Native to Managed Transition]  
user32.dll!74d862fa()   Unknown
user32.dll!74d86d3a()   Unknown
user32.dll!74d877d3()   Unknown
user32.dll!74d8789a()   Unknown
WindowsBase.ni.dll!6b4ceff4()   Unknown
[Managed to Native Transition]  
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame)   Unknown
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame)   Unknown
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore)   Unknown
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window)  Unknown
PresentationFramework.dll!System.Windows.Application.Run(System.Windows.Window window)  Unknown
PresentationFramework.dll!System.Windows.Application.Run()  Unknown
ProgramEditor.exe!ProgramEditor.App.Main()  C#
[Native to Managed Transition]  
mscoreei.dll!7143cc0b() Unknown
mscoree.dll!714b7f16()  Unknown
mscoree.dll!714b4de3()  Unknown
kernel32.dll!76d6338a() Unknown
ntdll.dll!773c9902()    Unknown
ntdll.dll!773c98d5()    Unknown

或者你可以将id存储在一个新变量中。

   <?php 

     $_POST['id'];

    ?>

如果您不确定您的帖子是否发送了任何值,您可以使用此功能。

<?php 

$id = $_POST['id'] 
echo($id);
?>